<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <title>回调页面</title>
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
</head>
<body>


<span style="font-size:22px;">登录中...</span>


<script>

    function getUrlParamValue(url, name) {
        let value = '';
        url.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(str, key, val) {
            if (key === name) {
                value = decodeURIComponent(val);
            }
        });
        return value;
    }

    function ssoLogin(){
        let code=getUrlParamValue(location.href,"code");
        $.ajax({
            url: '/sso/callback?code='+code,
            type: 'get',
            success: function(data){
                console.log(data)
                //把后台返回的 token 存起来使用
                location.href="/"
            },
            // 错误回调
            error: function(res){
                console.log('出错了..',res)
            },
        });
    }

    $(function (){
        /**
         * 为了演示流程 这里特意做了 延时操作
         */
        setTimeout(function (){
            ssoLogin();
        },1000);
    });


</script>
</body>
</html>